HA$PBExportHeader$u_cst_grillamain.sru
forward
global type u_cst_grillamain from userobject
end type
type dw_2 from datawindow within u_cst_grillamain
end type
type dw_1 from u_dw within u_cst_grillamain
end type
end forward

global type u_cst_grillamain from userobject
integer width = 1979
integer height = 2300
long backcolor = 67108864
string text = "none"
long tabtextcolor = 33554432
long picturemaskcolor = 536870912
event resize pbm_size
event ue_refrescar_row ( datawindow as_dw,  integer ai_row,  string as_button )
event ue_activa_opc ( boolean ab_activa_dw )
event ue_getbutton ( string as_button )
event ue_actualizar ( )
event ue_bloquear_refrescar ( boolean ab_param )
dw_2 dw_2
dw_1 dw_1
end type
global u_cst_grillamain u_cst_grillamain

type variables
long il_id ,il_ModifiedCount=0,il_codigo
integer ii_tool , ii_sw=0 ,ii_codigo
STRING is_button,is_codigo,is_columna,is_tipocolumna,is_tabla
boolean ib_sw = false, ib_refresh = false
s_parm istr_parm
datastore ids_datastore
//u_cst_m_toolcabemain    iuo_toolcabemain
window iw_parent
u_cst_toolbarstrip iuo_toolbar
//u_cst_grillamain iuo_grillamain
userobject iuo_tabmantomain

userobject iuo_grilla
end variables

forward prototypes
public function integer of_getwindow ()
public subroutine of_filtrar (string cadena, string columna)
public subroutine of_siguiente ()
public subroutine of_anterior ()
public subroutine of_primero ()
public subroutine of_ultimo ()
public function string of_getid ()
end prototypes

event resize;dw_1.Resize(newWidth, newHeight)
end event

event ue_refrescar_row(datawindow as_dw, integer ai_row, string as_button);integer li_fila 
choose case upper(as_button)
	case 'EDITAR','CONSULTAR'
		ib_refresh = true
		dw_1.object.data[ai_row] =as_dw.object.data 
		ib_refresh = false
	case 'NUEVO'
		//dw_1.accepttext( )
		ib_refresh = true
		dw_1.scrolltorow(dw_1.insertrow(0))
		dw_1.object.data[DW_1.ROWCOUNT()] = as_dw.object.data []
		iuo_tabmantomain.Dynamic Event  ue_setRow(DW_1.ROWCOUNT()) 
		dw_2.scrolltorow(dw_2.insertrow(0))
		dw_2.object.data[DW_2.ROWCOUNT()] = as_dw.object.data []
		ib_refresh = false
end choose

end event

event ue_activa_opc(boolean ab_activa_dw);
ib_sw = ab_activa_dw



end event

event ue_getbutton(string as_button);is_button = as_button
end event

event ue_actualizar();setpointer( HourGlass!)

choose case UPPER(is_tabla)
	case 'MOSAC'
		dw_1.retrieve( gs_idUser)		
	case	else 
		dw_1.retrieve( )
End choose

commit;
setpointer( Arrow!)
end event

event ue_bloquear_refrescar(boolean ab_param);ib_refresh = ab_param
end event

public function integer of_getwindow (); PowerObject	lpo_parent
Window lw_window

// loop thru parents until a window is found
lpo_parent = GetParent()
Do While lpo_parent.TypeOf() <> Window! and IsValid(lpo_parent)
	lpo_parent = lpo_parent.GetParent()
Loop

// set return to the window or null if not found
If IsValid (lpo_parent) Then
	lw_window = lpo_parent
Else
	SetNull(lw_window)
End If

iw_parent = lw_window

RETURN 1
end function

public subroutine of_filtrar (string cadena, string columna);string ls_cad,ls_tipo,ls_col
if cadena = ""  then
		this.dw_1.SetFilter("")
else
		ls_col = this.dw_1.describe(columna+'.name')
		ls_tipo=this.dw_1.describe(ls_col+'.coltype')
		ls_cad = 'Upper(string('+ls_col+')) like "%'+Upper(cadena)+'%" '
		this.dw_1.SetFilter(ls_cad)	
end if
this.dw_1.filter()
end subroutine

public subroutine of_siguiente ();dw_1.scrollnextrow( )
end subroutine

public subroutine of_anterior ();dw_1.scrollpriorrow( )
end subroutine

public subroutine of_primero ();dw_1.scrolltorow(0)
end subroutine

public subroutine of_ultimo ();dw_1.scrolltorow(dw_1.rowcount( ) )
end subroutine

public function string of_getid ();
string ls_data
if  dw_1.rowcount() <=0  then return ''
ls_data = dw_1.object.data[dw_1.getrow(),1]
return ls_data
end function

on u_cst_grillamain.create
this.dw_2=create dw_2
this.dw_1=create dw_1
this.Control[]={this.dw_2,&
this.dw_1}
end on

on u_cst_grillamain.destroy
destroy(this.dw_2)
destroy(this.dw_1)
end on

event constructor;string ls_dw ,is_tool

of_getwindow()

dw_1.Sort()
dw_1.Event RetrieveEnd(dw_1.RowCount())
dw_1.Event RowFocusChanged(1)

istr_parm        = message.powerobjectparm
iuo_toolbar 		=  istr_parm.auo_toolbarstrip
ids_datastore   = istr_parm.ads_menu
//iuo_tabmantomain = istr_parm.auo_tabmantomain
iuo_tabmantomain = istr_parm.auo_userobject
ls_dw              = ids_datastore.object.tDwGrid[1]
is_tabla           = ids_datastore.object.tTabla[1]
//if isnull(ls_dw) or ls_dw = '' then return 
//iuo_toolcabemain =  istr_parm.auo_toolcabemain
//iuo_toolcabemain = create u_cst_m_toolcabemain
dw_1.dataobject =ls_dw
dw_1.settransobject( sqlca);
dw_2.dataobject =ls_dw
choose case is_tabla
	case 'MOSAC'
			dw_1.retrieve(gs_iduser)
 CASE ELSE
			dw_1.retrieve();
end choose
commit;			
iuo_toolbar.DYNAMIC post event ue_cargar_columnas(dw_1)

end event

type dw_2 from datawindow within u_cst_grillamain
boolean visible = false
integer x = 571
integer y = 1040
integer width = 686
integer height = 400
integer taborder = 20
string title = "none"
boolean livescroll = true
borderstyle borderstyle = stylelowered!
end type

type dw_1 from u_dw within u_cst_grillamain
event ue_scrollvertical ( )
event ue_refresh ( )
event ue_scrolltorow ( integer ai_find )
integer width = 1957
integer height = 2280
integer taborder = 10
boolean hscrollbar = true
boolean vscrollbar = true
end type

event ue_scrollvertical();long ll_row
string ls_row

// Obtenga la primera fila de la p$$HEX1$$e100$$ENDHEX$$gina (FirstRowOnPage) sobre el datawindow
// primario. Dado que es un datawindow free form con una sola fila desplegada,
// la primera fila es la $$HEX1$$fa00$$ENDHEX$$nica visible. Despl$$HEX1$$e100$$ENDHEX$$cese hacia esa misma fila en el
// datawindow secundario.
//ls_row = this.Object.DataWindow.FirstRowOnPage
//ll_row = integer(ls_row)
//iuo_toolcabemain.DYNAMIC event ue_scroll(ll_row)
//dw_secondary.ScrollToRow(ll_row)
end event

event ue_refresh();string ls_columna,ls_tipo

dw_2.reset()
dw_1.RowsCopy(dw_1.GetRow(),dw_1.GetRow(), primary!, dw_2, 1, Primary!)

is_columna = dw_1.describe('#'+string(1)+'.name')
is_tipocolumna = dw_1.describe(is_columna+'.coltype')	
if left(is_tipocolumna,4)='char' then
	 is_codigo =dw_1.object.data[dw_1.GetRow(),1]
elseif is_tipocolumna='int' then
	 ii_codigo =dw_1.object.data[dw_1.GetRow(),1]
else
	il_codigo =dw_1.object.data[dw_1.GetRow(),1]
end if		
iuo_tabmantomain.Dynamic Event  ue_copy_fila(dw_2,dw_1.GetRow(),1)
iuo_tabmantomain.Dynamic Event  ue_ver_object(false) 


ib_sw = false ; il_ModifiedCount=0
//end if
end event

event ue_scrolltorow(integer ai_find);this.scrolltorow( ai_find)
ib_refresh = false
end event

event constructor;call super::constructor;// load sort service


If this.of_StartService("GridStyle") Then
	iSrv_GridStyle.of_SetStyle(True, True, True, True)

//	iSrv_GridStyle.of_AddAutoWidth("idgmenu")
//	iSrv_GridStyle.of_AddAutoWidth("id_name")
//	iSrv_GridStyle.of_AddAutoWidth("address")
//	iSrv_GridStyle.of_AddAutoWidth("city")
//	iSrv_GridStyle.of_AddAutoWidth("state")
//	iSrv_GridStyle.of_AddAutoWidth("company_name")

End If

// load selectrow service
If this.of_StartService("Select") Then
	iSrv_Select.of_SetSelectStyle("extend")
End If

end event

event doubleclicked;call super::doubleclicked;//if row > 0  then
//	iuo_toolbar.DYNAMIC event UE_BUTTONCLICKED('EDITAR')
//end if
//


end event

event scrollvertical;call super::scrollvertical;this.event post ue_scrollvertical()
end event

event clicked;call super::clicked;
if row > 0  and il_ModifiedCount = 0 then // ib_sw = false then
	if ib_refresh then return
	 this.event ue_refresh ()
end if
end event

event rowfocuschanged;//select rows
INTEGER li_verificar,li_find
If IsValid(iSrv_Select) Then
	iSrv_Select.Event RowFocusChanged(currentrow)
	If dw_1.rowcount() > 0 Then
		if ib_refresh then return
		il_ModifiedCount = iuo_tabmantomain.Dynamic Event ue_getdwmodified()
		if ib_sw and il_ModifiedCount > 0  then
			
			Choose Case iuo_tabmantomain.Dynamic Event ue_verificar_modified('')
				Case 3
					if left(is_tipocolumna,4)='char' then
						
						li_find = this.find('String(#1)="'+String(is_codigo)+'"' ,1,dw_1.rowcount())
					elseif is_tipocolumna='int' then
						
						li_find = this.find('String(#1)="'+String(ii_codigo)+'"' ,1,dw_1.rowcount())
					else
						
						 li_find = this.find('String(#1)="'+String(il_codigo)+'"' ,1,dw_1.rowcount())
					end if		
					post event ue_scrolltorow( li_find)
					ib_refresh = true
					return
				Case 2 
					il_ModifiedCount = 0
			End Choose
		end if
		If il_ModifiedCount = 0 then//ib_sw = False and
		   this.event  ue_refresh ()
		End If
	End If 
End If

end event

